<template>
  <view class="m-5 flex flex-col space-y-3">
    id: 1,
    quantity: 1,
    subtotal: 5,
    <u-button @click="handleQrCode">支付</u-button>
  </view>
</template>

<script setup lang="ts">

import api from "@/api";

const handleQrCode = () => {
  const productList = [
    {
      id: 1,
      quantity: 1,
      subtotal: 0.01,
    }
  ]
  api.pay.jsapiPay({
    productList: JSON.stringify(productList),
    total: 0.01,
    userId: 1,
    openId: 'o4Ctz6xP-JjUUnblc9wrVNN1GsSw'
  }).then((res: any) => {
    var orderInfo = {};
    if (res.data.code === 0) {
      uni.requestPayment({
        provider: "wxpay",  //固定值为"wxpay"
        timeStamp: res.data.data.timeStamp,
        nonceStr: res.data.data.nonceStr,
        package: res.data.data.packageVal,
        signType: res.data.data.signType,
        paySign: res.data.data.paySign,
        orderInfo: orderInfo,
        success: function (r) {
          console.log("支付成功");
          console.log(r)
        },
        fail: function (err) {
          console.log('支付失败:' + JSON.stringify(err));
        }
      })
    }
  })
}


</script>

<style scoped>

</style>